lib.use(['element', 'table', 'form'], function () {
    var table = layui.table;
    var layer = layui.layer;
    var form = layui.form;
    var jobLogTable;

    var STATUS_ENUM = {
        '0': '<span class="x-green">成功</span>'
        ,'1': '<span class="x-red"失败</span>'
    }

    // 渲染表格
    var renderTable = function (postData) {
        layer.load(2);
        jobLogTable = table.render({
            elem: '#jobLogTable'
            , url: ApiUtil.createUrl('/sys/scheduleLog/list')
            // 对分页请求的参数：page、limit重新设定名称
            ,request: LayuiExt.tableRequest
            , page: true
            , where: postData
            , cellMinWidth: 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                 {field: 'jobId', title: 'jobId', width: 60}
                , {field: 'beanName', title: 'Bean名称',  minwidth: 80}
                , {field: 'params', title: '参数', width: 120}
                , {field: 'status', title: '状态', width: 60, templet: function (row) {
                        var display = STATUS_ENUM[row.status + ''];
                        return display ? display : 'unknown';
                    }}
                , {field: 'times', title: '耗时(单位：毫秒)', width: 150}
                , {field: 'createTime', title: '执行时间', width: 150}

            ]]
            ,parseData: LayuiExt.tableParseData
            ,done: function () {
                layer.closeAll('loading');
            }
        });


    };

    form.on('submit(searchFilter)', function(data){
        var param = data.field;
        searchTable(param)
        return false;
    });

    searchTable();

    /**
     * 查询表格
     * @param params
     */
    function searchTable(params) {
        if(!params){
            params=$('#searchFrm')._serializeObject();
        }
        if (!jobLogTable) {
            jobLogTable = renderTable(params);
        } else {
            jobLogTable.reload({
                where: params
            })
        }
    }


});
